import Vue from 'vue'
import Router from 'vue-router'

import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
// 解决点击同一路由时报错
const routerPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error)
}
Vue.use(Router)

const router = new Router({
  mode: 'history',
  routes: [{
      path: '/',
      redirect: '/home',
    },
    {
      path: '/index',
      component: () => import('../pages/index.vue'),
      children: [{
          path: "",
          component: () => import('../pages/home.vue')
        },
        {
          path: "/home",
          name: '/home',
          component: () => import('../pages/home.vue')
        },
        {
          path: "/merchant_register",
          name: '/merchant_register',
          component: () => import('../pages/merchant_m/merchant_register.vue')
        },
        {
          path: "/merchant_loan",
          name: '/merchant_loan',
          component: () => import('../pages/merchant_m/merchant_loan.vue')
        },
      ]
    },
    {
      path: '/login',
      name: '/login',
      component: () => import('../pages/login.vue')
    },
    {
      path: '*',
      name: '/nulls',
      component: () => import('../pages/nulls.vue')
    }
  ]
})
router.beforeEach((to, form, next) => {
  NProgress.start()
  next()
})
router.afterEach(() => {
  NProgress.done()
})
export default router
